import request from './axios'
import { getStorage } from '@/utils/storage.js'

let modulesApis = []
const files = import.meta.glob('./modules/*.js', { eager: true })
// eslint-disable-next-line no-restricted-syntax
for (const key in files) {
    if (Object.hasOwnProperty.call(files, key)) {
        if (files[key].default) {
            modulesApis.push(...files[key].default)
        }
    }
}

export const apiUrls = new Map([...modulesApis])

// 常规请求头
export function http(apiName, params) {
    const [url, method, obj] = apiUrls.get(apiName)
    if (!obj || !obj.noNeedOrgId) {
        params = {
            orgId: getStorage('orgId'),
            ...params,
        }
    }
    return request[method](url, params, { ...obj })
}
